package com.jucai.pppeiyouclient.base;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.jucai.pppeiyouclient.comm.CommonMethod;

/**
 * Created by Kuky on 2017-04-14.
 */

public abstract class BasePopup extends PopupWindow {

    public BasePopup(Activity activity, int resourceId, final Window window, int animationStyle, View.OnClickListener onClickListener) {
        super(activity);
        this.setFocusable(true);
        this.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                CommonMethod.setWindowAlpha((float) 1.0, window);
            }
        });

        this.setContentView(getView(activity, resourceId, onClickListener));
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        ColorDrawable dw = new ColorDrawable(00000000);
        this.setBackgroundDrawable(dw);
        this.setAnimationStyle(animationStyle);
    }

    protected abstract View getView(Activity activity, int resource, View.OnClickListener onClickListener);


    public BasePopup(Activity activity, int resourceId, final Window window, int animationStyle, int width, View.OnClickListener onClickListener) {
        super(activity);
        this.setFocusable(true);
        this.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss() {
                CommonMethod.setWindowAlpha((float) 1.0, window);
            }
        });

        this.setContentView(getView(activity, resourceId, onClickListener));
        this.setWidth(width);
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        ColorDrawable dw = new ColorDrawable(00000000);
        this.setBackgroundDrawable(dw);
        this.setAnimationStyle(animationStyle);
    }

    public BasePopup(Activity activity, int resourceId, final Window window, int animationStyle, int width, int height, View.OnClickListener onClickListener) {
        super(activity);
        this.setFocusable(true);
        this.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                CommonMethod.setWindowAlpha((float) 1.0, window);
            }
        });

        this.setContentView(getView(activity, resourceId, onClickListener));
        this.setWidth(width);
        this.setHeight(height);
        ColorDrawable dw = new ColorDrawable(00000000);
        this.setBackgroundDrawable(dw);
        this.setAnimationStyle(animationStyle);

    }
}
